package com.zys.http.extension.completion.properties.language;


import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.util.ProcessingContext;
import com.zys.http.extension.completion.properties.psi.HttpPropertiesTypes;
import com.zys.http.tool.Placeholder;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @author zys
 * @since 2025-08-17
 */
public class HttpPropertiesCompletionContributor extends CompletionContributor {
    public HttpPropertiesCompletionContributor() {
        extend(CompletionType.BASIC, PlatformPatterns.psiElement(HttpPropertiesTypes.VALUE), HttpPropertiesCompletionProvider.INSTANCE);
    }

    private static final class HttpPropertiesCompletionProvider extends CompletionProvider<CompletionParameters> {
        private static final HttpPropertiesCompletionProvider INSTANCE = new HttpPropertiesCompletionProvider();
        private static final String[] KEYWORDS = new HashSet<>(Placeholder.keywords()).toArray(new String[0]);


        @Override
        protected void addCompletions(@NotNull CompletionParameters parameters,
                                      @NotNull ProcessingContext context,
                                      @NotNull CompletionResultSet result) {
            result.addAllElements(Arrays.stream(KEYWORDS).map(LookupElementBuilder::create).toList());
        }
    }
}
